var avatarUp0 = "";

function iconTypeChange() {
    avatarUp0 = new $IconUpload("avatar0");
    avatarUp0.initIcon();
}

$(function () {
    iconTypeChange();
});

function storageRootCanal() {
    var reservationsId=document.getElementById("reservationsId").value;
    var num=document.getElementById("num").value;
    var customerName=$("#customerName",parent.document).val();
    var treatmentTypes=document.getElementById("treatmentTypes").value;
    var consumptionAmount=document.getElementById("consumptionAmount").value;
    var toothPositionA = document.getElementById("leftUp").innerHTML;
    var toothPositionB = document.getElementById("rightUp").innerHTML;
    var toothPositionC = document.getElementById("leftDown").innerHTML;
    var toothPositionD = document.getElementById("rightDown").innerHTML;
    var doctor = $("#doctor").val();
    var nurse = $("#nurse").val();
    var toothPosition = "";
    if (toothPositionA.length <= 0 && toothPositionB.length <= 0 && toothPositionC.length <= 0 && toothPositionD.length <= 0) {
        Feng.error("牙位不能为空！");
        return false;
    }
    if ((toothPositionA.length + toothPositionB.length + toothPositionC.length + toothPositionD.length) > 1) {
        Feng.error("牙位只能选择一个！");
        return false;
    }
    if (toothPositionA.length > 0) {
        toothPosition = "A" + toothPositionA;
    } else if (toothPositionB.length > 0) {
        toothPosition = "B" + toothPositionB;
    } else if (toothPositionC.length > 0) {
        toothPosition = "C" + toothPositionC;
    } else if (toothPositionD.length > 0) {
        toothPosition = "D" + toothPositionD;
    }
    if($("#avatar0PreId").children().length <= 0){
        Feng.error("请补全照片！");
        return false;
    }
    if(treatmentTypes == "" || treatmentTypes == undefined){
        Feng.error("请选择治疗种类！");
        return false;
    }
    if(doctor==null || doctor=="" || doctor==undefined){
        Feng.error("请选择医生！");
        return false;
    }
    if(consumptionAmount == "" || consumptionAmount == undefined){
        Feng.error("请输入消费金额！");
        return false;
    }
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/storageRootCanal",
        type: "post",
        data: {
            "reservationsId": reservationsId,
            "num": num,
            "treatmentTypes": treatmentTypes,
            "consumptionAmount": consumptionAmount,
            "toothPositionA": toothPositionA,
            "toothPositionB": toothPositionB,
            "toothPositionC": toothPositionC,
            "toothPositionD": toothPositionD,
            "toothPosition": toothPosition,
            "doctor": doctor,
            "nurse": nurse,
            "customerName": customerName
        },
        success: function (data) {
            Feng.success('操作成功!');
            window.parent.RootCanalScoreTable.table.refresh();
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }
    })
}

function subRootCanal() {
    var reservationsId=document.getElementById("reservationsId").value;
    var num=document.getElementById("num").value;
    var treatmentTypes=document.getElementById("treatmentTypes").value;
    var consumptionAmount=document.getElementById("consumptionAmount").value;
    var toothPositionA = document.getElementById("leftUp").innerHTML;
    var toothPositionB = document.getElementById("rightUp").innerHTML;
    var toothPositionC = document.getElementById("leftDown").innerHTML;
    var toothPositionD = document.getElementById("rightDown").innerHTML;
    var toothPosition = "";
    var customerName=$("#customerName",parent.document).val();
    var doctor = $("#doctor").val();
    var nurse = $("#nurse").val();
    if(doctor===null || doctor==="" || doctor===undefined){
        Feng.error("医生不能为空！");
        return false;
    }
    if(nurse===null || nurse==="" || nurse===undefined){
        Feng.error("护士不能为空！");
        return false;
    }
    if (toothPositionA.length <= 0 && toothPositionB.length <= 0 && toothPositionC.length <= 0 && toothPositionD.length <= 0) {
        Feng.error("牙位不能为空！");
        return false;
    }
    if ((toothPositionA.length + toothPositionB.length + toothPositionC.length + toothPositionD.length) > 1) {
        Feng.error("牙位只能选择一个！");
        return false;
    }
    if (toothPositionA.length > 0) {
        toothPosition = "A" + toothPositionA;
    } else if (toothPositionB.length > 0) {
        toothPosition = "B" + toothPositionB;
    } else if (toothPositionC.length > 0) {
        toothPosition = "C" + toothPositionC;
    } else if (toothPositionD.length > 0) {
        toothPosition = "D" + toothPositionD;
    }
    if($("#avatar0PreId").children().length <= 0){
        Feng.error("请补全照片！");
        return false;
    }
    if(treatmentTypes == "" || treatmentTypes == undefined){
        Feng.error("请选择治疗种类！");
        return false;
    }
    if(consumptionAmount == "" || consumptionAmount == undefined){
        Feng.error("请输入消费金额！");
        return false;
    }
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/subRootCanal",
        type: "post",
        data: {
            "reservationsId": reservationsId,
            "num": num,
            "treatmentTypes": treatmentTypes,
            "consumptionAmount": consumptionAmount,
            "toothPositionA": toothPositionA,
            "toothPositionB": toothPositionB,
            "toothPositionC": toothPositionC,
            "toothPositionD": toothPositionD,
            "toothPosition": toothPosition,
            "doctor": doctor,
            "nurse": nurse,
            "customerName": customerName
        },
        success: function (data) {
            Feng.success('操作成功!');
            window.parent.RootCanalScoreTable.table.refresh();
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }
    })
}

function rootCanalClose() {
    parent.layer.close(parent.layer.getFrameIndex(window.name));
}

$('#avatar0PreId').on('click', '.cp_img_delete', function (e) {
    e.stopPropagation();
    var that = this;
    var id = $(that).parent().attr("id");
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/deleteRootCanalImgs",
        type: "post",
        data: {"id": id},
        success: function (data) {
            $(that).parent().remove();
            Feng.success("删除成功！");
        },
        error: function (data) {
            alert("删除失败！");
        }
    });
});